<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多个事件添加器示例</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f4f7fc;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            color: #333;
        }

        .container {
            text-align: center;
            padding: 30px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            width: 300px;
        }

        h1 {
            font-size: 24px;
            margin-bottom: 20px;
        }

        .btn {
            background-color: #4CAF50;
            color: white;
            padding: 12px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s ease;
        }

        .btn:hover {
            background-color: #45a049;
        }

        .status {
            margin-top: 20px;
            font-size: 18px;
            font-weight: bold;
        }

        .status.active {
            color: #28a745;
        }

        .status.inactive {
            color: #dc3545;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>按钮状态切换</h1>
        <button id="toggleButton" class="btn">点击我切换状态</button>
        <div id="status" class="status inactive">状态：未激活</div>
    </div>

    <script>
        // 事件监听函数
        const addMultipleListeners = (el, eventType, listener, options) =>
            eventType.forEach(type =>
                el?.addEventListener(type, listener, options)
            );

        // 获取按钮和状态元素
        const button = document.getElementById('toggleButton');
        const status = document.getElementById('status');

        // 定义按钮点击事件
        const handleClick = () => {
            if (status.classList.contains('inactive')) {
                status.classList.remove('inactive');
                status.classList.add('active');
                status.textContent = '状态：已激活';
            } else {
                status.classList.remove('active');
                status.classList.add('inactive');
                status.textContent = '状态：未激活';
            }
        };

        // 定义按钮鼠标悬停事件
        const handleMouseOver = () => {
            button.style.backgroundColor = '#2396ef'; // 改变按钮的颜色
        };

        // 定义鼠标移出事件
        const handleMouseOut = () => {
            button.style.backgroundColor = '#4CAF50'; // 恢复按钮的颜色
        };

        // 为按钮添加多个事件监听
        addMultipleListeners(button, ['click', 'mouseover', 'mouseout'], (event) => {
            if (event.type === 'click') {
                handleClick();
            } else if (event.type === 'mouseover') {
                handleMouseOver();
            } else if (event.type === 'mouseout') {
                handleMouseOut();
            }
        });

    </script>

</body>

</html>